/**
 * A generic confirmation for risky actions.
 * Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function
*/
'use strict';

angular.module('afasApp')
.directive('ngReallyClick', ['dialogs', function(dialogs) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      element.bind('click', function() {
        var message = attrs.ngReallyMessage;
        // var dlg = dialogs.confirm();
        // dlg.result.then(function(btn){
        //   console.log(attrs.ngReallyClick);
        //   // if (!scope.$$phase && !scope.$root.$$phase){
        //     // scope.$apply();
        //     scope.$apply(attrs.ngReallyClick);
        //   // }
        //   // $scope.confirmed = 'You confirmed "Yes."';
        // },function(btn){
        //   // $scope.confirmed = 'You confirmed "No."';
        // });
        if (message && confirm(message)) {
          scope.$apply(attrs.ngReallyClick);
        }
      });
    }
  }
}]);